package com.lt.thread;


/**
 *
 * @version 1.00
 * @Author lt
 * @Date 2020/5/20 14:32
 **/
public class ThreadSafe extends Thread {

    public volatile boolean exit = false;

    @Override
    public void run() {
//        while (!exit){
//            System.out.println("run");
//        }
        // 非阻塞过程中通过判断中断标志来退出
        while (!isInterrupted()){
            try {
                Thread.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
                break;// 捕获之后跳出循环
            }
        }
    }

    public static void main(String[] args) {
        ThreadSafe threadSafe = new ThreadSafe();
        threadSafe.run();
    }

}
